package br.com.tcc.automacao.util;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONString;
import org.json.JSONStringer;
import org.json.JSONWriter;


public class Uteis {

	public static boolean ehNumero(String string){
		return string.matches("[0-9]*");		
	}
	
	public static int converterParaInteger(String string){
		return Integer.parseInt(string);
	}
	public static Long converterParaLong(String string){
		return Long.parseLong(string);
	}

	public static void respostaJson(String respostaJSON, HttpServletRequest request, HttpServletResponse response) throws Exception{
	       response.setContentType("application/json; charset=UTF-8");
	        PrintWriter printout = response.getWriter();

	        printout.write(respostaJSON);
	        printout.flush();
	    }
	
	public static boolean converterParaBoolean(String string){
	    boolean b = false;
	    if(string != null && string.equals("true")){
		b = true;
	    }else {
		b = false;
	    }
	    	return b;
	}
}
